package view;

import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

public class MenuBar extends JMenuBar {

	private static final long serialVersionUID = 6691905884404830530L;
	private JMenu fileMenu, colorMenu; 
	private JMenuItem fileOpenMI, fileEndProgramMI, colorGenetic, colorPrev, colorNext;
	
	public MenuBar() {
		super();
		
		fileMenu = new JMenu("File");
		fileOpenMI = new JMenuItem("Open");
		fileEndProgramMI = new JMenuItem("Close");
		fileOpenMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
		fileEndProgramMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK));
		fileMenu.add(fileOpenMI);
		fileMenu.add(fileEndProgramMI);
		add(fileMenu);
		
		colorMenu = new JMenu("Color");
		colorGenetic = new JMenuItem("Color genetic");
		colorGenetic.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
		colorPrev = new JMenuItem("Color prev");
		colorNext = new JMenuItem("Color next");
		
		colorMenu.add(colorGenetic);
		colorMenu.add(colorPrev);
		colorMenu.add(colorNext);
		add(colorMenu);
	}
	
	/****** LISTENERS *******/
	
	public void addFileOpenActionListener (ActionListener al) {
		fileOpenMI.addActionListener(al);
	}
	
	public void addFileEndProgramActionListener (ActionListener al) {
		fileEndProgramMI.addActionListener(al);
	}
	
	public void addColorGeneticActionListener (ActionListener al) {
		colorGenetic.addActionListener(al);
	}
	
	public void addColorNextActionListener (ActionListener al) {
		colorNext.addActionListener(al);
	}
	
	public void addColorPrevActionListener (ActionListener al) {
		colorPrev.addActionListener(al);
	}
	
	public void setButtonsEnability (boolean isGraphLoaded) {
		if (isGraphLoaded) {
			colorMenu.setEnabled(true);
		} else {
			colorMenu.setEnabled(false);
		}
	}
}
